package cn.codeforfun.exchage;

import cn.codeforfun.consts.SessionConsts;
import cn.codeforfun.prize.Prize;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/18 0018.
 */
@Controller
@RequestMapping("/exchange")
public class ExchangeController {
    @Autowired
    private ExchangeService exchangeService;


    @RequestMapping("/showPrice")
    @ResponseBody
    public Map showPrice(HttpSession session) throws WxErrorException {
        Map map = exchangeService.showPrice(session);
        return map;
    }

    @RequestMapping("/getCode")
    @ResponseBody
    public Map getCode(String code) {
        if (code == null) return null;
        Integer cod;
        try {
            cod = Integer.valueOf(code);
        } catch (NumberFormatException e) {
            return null;
        }
        Map map = exchangeService.getCode(cod);
        return map;
    }

    @RequestMapping("/hasExchange")
    @ResponseBody
    public Map hasExchange(String voteId, String followerId) {
        exchangeService.hasExchange(voteId, followerId);
        return new HashMap();
    }
}
